#!/usr/bin/python3
#coding:utf-8
__author__ = 'merci'
import pymysql
import time
import csv

def connectMysql():
    conn = False
    try:
        conn = pymysql.Connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='sulao', charset='utf8')
    except:
        print("Connect MySQL failed !")
        conn = False
    return conn
def getList():
    cur = connectMysql().cursor()
    sql = '''SELECT * FROM zbp_post WHERE log_Status=0 ORDER BY log_ID ASC'''
    cur.execute(sql)
    dat = cur.fetchall()
    return dat

if __name__ == "__main__":
    start_time = time.time()
    csvfile = open('article.csv', 'w', newline='')
    cvwrite = csv.writer(csvfile)
    cvwrite.writerow(['id','标题','简介'])
    for tu in getList():
        cvwrite.writerow((tu[0], tu[9], tu[12]))
    end_time = time.time()
    print("写入完成，耗时 %.3fs" % (end_time - start_time))